local skill = fk.CreateSkill{
  name = "tea__fujie",
}
Fk:loadTranslationTable{
  ["tea__fujie"] = "符节",
  [":tea__fujie"] = "出牌阶段限一次，你可以重铸至少两张点数连续的牌，视为对至多等量角色使用一张【桃】，然后你令其中体力值不小于X的角色依次选择"..
  "一项（X为你以此法重铸的牌数）：1.重铸一张点数于此区间的牌；2.受到 2 点雷电伤害。",
  ["#tea__fujie-prompt"] = "符节：你可以重铸至少两张点数连续的牌，视为对至多等量角色使用一张【桃】",
  ["#tea__fujie-choose"] = "符节：重铸一张点数位于 %arg 的牌，或点取消并受到2点雷电伤害",
}
---@param ids integer[]|integer
---@return integer[]
local getNumber = function(ids)
  if type(ids) == "number" then
    return {Fk:getCardById(ids).number}
  elseif type(ids) == "table" then
    return table.map(ids, function(id)
      return Fk:getCardById(id).number
    end)
  end
  return {}
end
local isEqualDifferenceSeries = function(list, difference)
  local dif = difference or 1
  table.sort(list)
  local n
  for _, i in ipairs(list) do
    if not n then
      n = i 
    elseif i ~= n + dif then
      return false
    else
      n = i
    end
  end
  return true
end
---@type ActiveSkillSpec
local fujie = {
  anim_type = "special",
  prompt = "#tea__fujie-prompt",
  min_card_num = 2,
  min_target_num = 1,
  card_filter = function(self, player, to_select, selected)
    if #selected == 0 then return true 
    else
      local list = table.clone(selected)
      table.insertIfNeed(list, to_select)
      return isEqualDifferenceSeries(getNumber(list))
    end
  end,
  target_filter = function(self, player, to_select, selected, selected_cards)
    if #selected < #selected_cards then
      return not player:prohibitUse(Fk:cloneCard("peach")) and to_select:isWounded()
    end
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(skill.name, Player.HistoryTurn) == 0 and table.find(Fk:currentRoom().alive_players, function(p)
      return not player:isProhibited(p, Fk:cloneCard("peach"))
    end)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local tos = effect.tos
    local cards = effect.cards
    room:sortByAction(tos)
    room:recastCard(cards, player, skill.name)
    local c = Fk:cloneCard("peach")
    c.skillName = skill.name
    local use = {
      from = player,
      tos = tos,
      card = c,
    }
    room:useCard(use)
    for _, to in ipairs(tos) do
      if not player.dead and player.hp >= #cards then
        if player:isNude() then
          room:damage{
            to = to,
            damage = 2,
            damageType = fk.ThunderDamage,
            skillName = skill.name,
          }
        else
          local ids = table.filter(to:getCardIds("he"), function(id)
            return (table.find(getNumber(cards), function(num)
              return num <= getNumber(id)[1]
            end) or 0) > 0 and (table.find(getNumber(cards), function(num)
              return num >= getNumber(id)[1]
            end)) or 0 > 0
          end)
          local cnumbers = getNumber(cards)
          table.sort(cnumbers)
           local cid = room:askToCards(to, {
            min_num = 1,
            max_num = 1,
            include_equip = true,
            pattern = tostring(Exppattern{id = ids}),
            skill_name = skill.name,
            prompt = "#tea__fujie-choose:::" .. tostring(cnumbers[1]) .. "~" .. tostring(cnumbers[#cnumbers])
           })
          if #cid == 1 then
            room:recastCard(cid, to, self.name)
          else
            room:damage{
              to = to,
              damage = 2,
              damageType = fk.ThunderDamage,
              skillName = skill.name,
            }
          end
        end
      end
    end
  end,
}
skill:addEffect("active", fujie)
return skill